package strings.exercise;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by cody on 16/1/13.
 */
public class Exercise10 {

    public static void main(String[] args) {
        String inputString = "Java now has regular expressions";
        String[] regs = {"^Java", "\\Breg.*", "n.w\\s+h(a|i)s", "s?", "s*", "s+", "s{4}", "s{1}.", "s{0,3}"};
        for (int i = 0; i < regs.length; i++) {
            Pattern pattern = Pattern.compile(regs[i]);
            Matcher matcher = pattern.matcher(inputString);
            if (matcher.find()) {
                System.out.println((i+1) + ". Match " + matcher.group() + " at positions " + matcher.start() + "-" + matcher.end());
            }
        }
    }

}
